import axios, {
  AxiosInstance,
  AxiosResponse,
  InternalAxiosRequestConfig,
} from "axios";
import { getToken } from "./token";
const request: AxiosInstance = axios.create({
  baseURL: "http://127.0.0.1:8888/api/private/v1/",
  timeout: 5000,
});

request.interceptors.request.use((config: InternalAxiosRequestConfig) => {
  if (getToken()) {
    config.headers.Authorization = getToken();
  }
  return config;
});

request.interceptors.response.use(
  (response: AxiosResponse) => {
    return response.data;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export default request;
